﻿using System;
using System.Data;
using System.Data.SqlClient;


namespace LRSTaxServices.Biz
{
    public class AppSettings
    {
        #region Types - None
        #endregion

        #region Constants - None
        #endregion

        #region Public Propertes

        /// <summary>
        /// The application's version string. TODO: Derive this from web.config.
        /// </summary>
        public static string AppVersion
        {
            get { return (null); }
        }


        /// <summary>
        /// The active database connection string.
        /// </summary>
        public static string DbConnStr
        {
            get
            {
                if (_dbConnStr == null)
                {
                    // Attempt to set the default connection string from web.config
                    if ((System.Web.Configuration.WebConfigurationManager.ConnectionStrings != null) &&
                        (System.Web.Configuration.WebConfigurationManager.ConnectionStrings["PrimaryDbConn"] != null))
                    {
                        _dbConnStr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["PrimaryDbConn"].ConnectionString;
                    }
                    // Attempt to set the default connection string from app.config
                    else if (System.Configuration.ConfigurationManager.AppSettings["PrimaryDbConn"] != null)
                    {
                        _dbConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["PrimaryDbConn"].ConnectionString;
                    }
                }
                return (_dbConnStr);
            }
            set
            {
                _dbConnStr = value;
            }
        } private static string _dbConnStr = null;


        /// <summary>
        /// The site's public, fully-qualified URL.
        /// </summary>
        public static string AppPublicURL
        {
            get { return ("http://www.GlobalTechUS.com"); }
        }


        /// <summary>
        /// The app relative path to the site's Home page.
        /// </summary>
        public static string HomePage
        {
            get { return ("~index.aspx"); }
        }


        /// <summary>
        /// The app relative path to the site's administrative home page.
        /// </summary>
        public static string AdminHomePage
        {
            get { return ("~/admin/index.aspx"); }
        }


        /// <summary>
        /// The app relative path to the site's Login page.
        /// </summary>
        public static string LoginPage
        {
            get { return ("~/login.aspx"); }
        }


        /// <summary>
        /// The app relative path of the site's Images directory.
        /// </summary>
        public static string ImageRoot
        {
            get { return ("~/images"); }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Returns a database connection object derived from the web.config -> ConnectionStrings -> 'PrimaryDbConn' setting.
        /// </summary>
        public static SqlConnection GetDbConn()
        {
            return (new System.Data.SqlClient.SqlConnection(AppSettings.DbConnStr));
        }


        #endregion
    }
}
